package com.sugar.follow.up.module.business.service.userpatienttags;

import cn.hutool.core.collection.CollUtil;
import com.sugar.follow.up.module.business.dal.dataobject.userpatienttags.UserPatientTagsDO;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import com.sugar.follow.up.module.business.dal.mysql.userpatienttags.UserPatientTagsMapper;

import java.util.Collections;
import java.util.List;

/**
 * 就诊人标签 Service 实现类
 *
 * @author Ysugar
 */
@Service
@Validated
public class UserPatientTagsServiceImpl implements UserPatientTagsService {

    @Resource
    private UserPatientTagsMapper userPatientTagsMapper;

    @Override
    public void createUserPatientTags(String[] tags, Long patientId) {
        userPatientTagsMapper.insert(new UserPatientTagsDO().setPatientId(patientId).setTag(CollUtil.newArrayList(tags[0], tags[1])));
    }

    @Override
    public void clear(Long patientId) {
        userPatientTagsMapper.delete(UserPatientTagsDO::getPatientId, patientId);
    }

    @Override
    public List<UserPatientTagsDO> getAllByPatientId(Long patientId) {
        return userPatientTagsMapper.selectList(UserPatientTagsDO::getPatientId, patientId);
    }
}